﻿using System.Linq;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Vent.ViewModels.Tools
{
    [DataContract]
    public class PolylineTool : Tool
    {
        protected Polyline Polyline;

        public override void AddPoint(Point point, bool start)
        {
            if (start) Polyline = StartPolyline();
            if (Polyline == null) return;
            Polyline.Points.Add(point);
            var minX = Polyline.Points.Min(p => p.X);
            var minY = Polyline.Points.Min(p => p.Y);
            Polyline.Stroke = GetAlignedBrush(new Point(minX, minY));
        }

        protected Polyline StartPolyline()
        {
            var polyline = new Polyline
            {
                Opacity = Opacity,
                StrokeThickness = Tickness,
                StrokeDashCap = PenLineCap.Round,
                StrokeLineJoin = PenLineJoin.Round,
                StrokeStartLineCap = PenLineCap.Round,
                StrokeEndLineCap = PenLineCap.Round,
            };

            TouchViewModel.AddTouch(polyline);
            return polyline;
        }
    }
}
